package com.lyj.controller;

import com.lyj.pojo.Nurse;
import com.lyj.pojo.NurseSalary;
import com.lyj.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class SalaryController {

    @Autowired
    SalaryService salaryService;
//查询所有人的所有薪资
    @RequestMapping("/queryAllSalary")
    @ResponseBody
    public List<NurseSalary> queryAllSalary(){
        List<NurseSalary> nurseSalaryList = salaryService.queryAllSalary();
        return nurseSalaryList;

    }
    //关键字搜索
    @RequestMapping("/querySalaryByName")
    @ResponseBody
    public List<NurseSalary> querySalaryByName(String username){
        List<NurseSalary> nurseSalaryList = salaryService.querySalaryByName(username);
        return nurseSalaryList;
    }
//修改护工薪资信息
    @RequestMapping("/updateBySalaryId")
    @ResponseBody
    public Boolean updateBySalaryId(NurseSalary nurseSalary){
        Boolean aBoolean = salaryService.updateBySalaryId(nurseSalary);
        return aBoolean;

    }

    //删除护工薪资信息
    @RequestMapping("/delBySalaryId")
    @ResponseBody
    public Boolean delBySalaryId(int salaryId){
        Boolean aBoolean = salaryService.delBySalaryId(salaryId);
        return aBoolean;

    }
//增加护工薪资
    @RequestMapping("/addSalaryByNurseId")
    @ResponseBody
    public Boolean addSalaryByNurseId(int nurseId,String username,String salary,String deductionFee,
                                      String payStatus, String remarks, String realWages,String month ) throws ParseException {

        NurseSalary nurseSalary = new NurseSalary();
        nurseSalary.setNurseId(nurseId);
        nurseSalary.setUsername(username);
        nurseSalary.setSalary(Double.valueOf(salary.toString()));
        nurseSalary.setDeductionFee(Double.valueOf(deductionFee.toString()));
        nurseSalary.setPayStatus(payStatus);
        nurseSalary.setRemarks(remarks);
        nurseSalary.setRealWages(Double.valueOf(realWages.toString()));

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = format.parse(month+1);
        nurseSalary.setMonth(date);


        Boolean aBoolean = salaryService.addSalaryByNurseId(nurseSalary);
        return aBoolean;

    }


}
